package org.flexthinker.binding.ui.form.binding.flex
{
    import mx.core.UIComponent;
    import mx.utils.StringUtil;

    import org.flexthinker.binding.bean.UpdateStrategy;
    import org.flexthinker.binding.ui.form.binding.support.FieldBinder;

    /**
     *  Binder implementation for all visual components extending <code>TextBase</code> or
     * <code>SkinnableTextBase</code>, which expose a <code>text</code> property.
     * These components are: <code>TextArea</code>, <code>TextInput</code>, <code>Label</code> and
     * <code>RichText</code>.
     *
     * <code>DefaultFlexBinderFactory</code> automatically serves this <code>TextBinder</code> for these components.
     *
     *  <code>TextBinder</code> generates a <code>Binding</code> on the <code>text</code> property of the
     *  </code>component</code>. The <code>UpdateStrategy</code> is <code>READ_WRITE</code>.
     */
    public class TextBinder extends FieldBinder
    {
        public function TextBinder(component:UIComponent, formProperty:String):void
        {
            super(component, formProperty);
            if ( ! component.hasOwnProperty("text"))
            {
                throw new ArgumentError( StringUtil.substitute( "Could not use TextBinder on {0}", component) );
            }
            super.componentProperty = "text";
            super.updateStrategy = UpdateStrategy.READ_WRITE;
        }
    }
}
